package com.ozo.boot.common.file;

import com.ozo.boot.common.file.constant.FileStoreTypeEnum;
import com.ozo.boot.common.file.service.FileTemplate;
import com.ozo.boot.common.file.service.FileTemplateImpl;
import com.ozo.boot.common.file.strategy.*;
import com.ozo.boot.common.file.config.FileStoreProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 验证码自动配置
 *
 * @author qiangesoft
 * @date 2024-07-03
 */
@Configuration
@EnableConfigurationProperties(FileStoreProperties.class)
public class FileAutoConfiguration {

    @Bean
    public FileStrategy fileStrategy(FileStoreProperties fileStoreProperties) {
        FileStoreTypeEnum type = fileStoreProperties.getType();
        switch (type) {
            case MINIO -> {
                return new MinioStrategyImpl(fileStoreProperties);
            }
            case ALIYUN -> {
                return new AliyunStrategyImpl(fileStoreProperties);
            }
            case QINIU -> {
                return new QiniuStrategyImpl(fileStoreProperties);
            }
            default -> {
                return new LocalStrategyImpl(fileStoreProperties);
            }
        }
    }

    @Bean
    public FileTemplate fileService(FileStrategy fileStrategy) {
        return new FileTemplateImpl(fileStrategy);
    }

}
